package ru.urfc.portal.ui.client.renderers;

import static ru.urfc.portal.ui.client.Constants.*;

import com.extjs.gxt.ui.client.data.ModelData;
import com.google.gwt.dom.client.Element;

import ru.urfc.portal.ui.client.descriptor.GridField;

public class FrequenciesListRenderer extends IntegerRenderer {

	public FrequenciesListRenderer(GridField field, Element element) {
		super(field, element);
		setMHzFormatForList();
	}

	@Override
	public String render(ModelData modelData) {
		String listAsStr = field.getValue(modelData);
		if (listAsStr == null) {
			return "";
		}
		String[] list = listAsStr.split(NUMBER_LIST_SEPARATOR);
		String result = "";
		for (String item: list) {
			if (result.length() != 0) {
				result += "; ";
			}
			result += render(new Double(item.trim()));
		}
		return result + " МГц";
	}

}
